package com.jilian.mydemo.modul.exam.ui;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jilian.mydemo.MyApplication;
import com.jilian.mydemo.R;
import com.jilian.mydemo.base.BaseActivity;
import com.jilian.mydemo.common.dto.CommiteDto;
import com.jilian.mydemo.modul.user.activity.RealNameAuthenticationActivity;
import com.jilian.mydemo.utils.ToastUitl;

public class ExamResultActivity  extends BaseActivity {
    private ImageView ivHead;
    private TextView tvResult;
    private TextView tvScore;
    private TextView tvNext;
    private TextView tvError;

    private CommiteDto dto;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MyApplication.addActivity(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        MyApplication.removeActivity(this);
    }

    @Override
    protected void createViewModel() {

    }

    @Override
    public int intiLayout() {
        return R.layout.examresult_activity;
    }

    @Override
    public void initView() {
        setNormalTitle("考试结果", v -> finish());
        ivHead = (ImageView) findViewById(R.id.iv_head);
        tvResult = (TextView) findViewById(R.id.tv_result);
        tvScore = (TextView) findViewById(R.id.tv_score);
        tvNext = (TextView) findViewById(R.id.tv_next);
        tvError = (TextView) findViewById(R.id.tv_error);
    }

    @Override
    public void initData() {
        dto = (CommiteDto) getIntent().getSerializableExtra("data");
        if(dto!=null){
            tvScore.setText("得分："+dto.getScore()+"分");
            //是否通过，0未通过，1通过
            if(dto.getIsPass()==0){
                tvScore.setTextColor(Color.parseColor("#f94d4d"));
                tvResult.setText("未通过考试");
                tvNext.setText("重新考试");
                ivHead.setImageResource(R.drawable.image_icon_failed);
            }
        }
        else{
            ToastUitl.showImageToastTips("客户端异常");
        }
    }

    @Override
    public void initListener() {
        tvError.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(ExamResultActivity.this, CheckWrongTopicActivity.class));
            }
        });
        tvNext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(dto.getIsPass()==1){
                    startActivity(new Intent(ExamResultActivity.this, RealNameAuthenticationActivity.class));
                }
                else{
                    finish();
                    startActivity(new Intent(ExamResultActivity.this, AnswerQuestionsActivity.class));
                }

            }
        });

    }
}
